<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="通行介质 1位数字
1-OBU
2-CPC卡
3-纸券
9-无通行介质" prop="mediatype">
      <el-input v-model="dataForm.mediatype" placeholder="通行介质 1位数字
1-OBU
2-CPC卡
3-纸券
9-无通行介质"></el-input>
    </el-form-item>
    <el-form-item label="介质编码" prop="mediano">
      <el-input v-model="dataForm.mediano" placeholder="介质编码"></el-input>
    </el-form-item>
    <el-form-item label="交易支付方式:1.出口ETC通行;2.出口ETC刷卡通行." prop="transpaytype">
      <el-input v-model="dataForm.transpaytype" placeholder="交易支付方式:1.出口ETC通行;2.出口ETC刷卡通行."></el-input>
    </el-form-item>
    <el-form-item label="OBU单/双片标识" prop="obusign">
      <el-input v-model="dataForm.obusign" placeholder="OBU单/双片标识"></el-input>
    </el-form-item>
    <el-form-item label="OBU序号编码" prop="obuid">
      <el-input v-model="dataForm.obuid" placeholder="OBU序号编码"></el-input>
    </el-form-item>
    <el-form-item label="ETC卡编号" prop="cardid">
      <el-input v-model="dataForm.cardid" placeholder="ETC卡编号"></el-input>
    </el-form-item>
    <el-form-item label="ETC卡类别" prop="etccardtype">
      <el-input v-model="dataForm.etccardtype" placeholder="ETC卡类别"></el-input>
    </el-form-item>
    <el-form-item label="出口交易时间" prop="extime">
      <el-input v-model="dataForm.extime" placeholder="出口交易时间"></el-input>
    </el-form-item>
    <el-form-item label="实际车辆车牌号码+颜色" prop="vehicleid">
      <el-input v-model="dataForm.vehicleid" placeholder="实际车辆车牌号码+颜色"></el-input>
    </el-form-item>
    <el-form-item label="收费车型" prop="vehicletype">
      <el-input v-model="dataForm.vehicletype" placeholder="收费车型"></el-input>
    </el-form-item>
    <el-form-item label="车种" prop="vehicleclass">
      <el-input v-model="dataForm.vehicleclass" placeholder="车种"></el-input>
    </el-form-item>
    <el-form-item label="出口重量" prop="exweight">
      <el-input v-model="dataForm.exweight" placeholder="出口重量"></el-input>
    </el-form-item>
    <el-form-item label="轴数" prop="axlecount">
      <el-input v-model="dataForm.axlecount" placeholder="轴数"></el-input>
    </el-form-item>
    <el-form-item label="入口车道编号" prop="entolllaneid">
      <el-input v-model="dataForm.entolllaneid" placeholder="入口车道编号"></el-input>
    </el-form-item>
    <el-form-item label="入口车道hex" prop="entolllanehex">
      <el-input v-model="dataForm.entolllanehex" placeholder="入口车道hex"></el-input>
    </el-form-item>
    <el-form-item label="入口交易发生的时间" prop="entime">
      <el-input v-model="dataForm.entime" placeholder="入口交易发生的时间"></el-input>
    </el-form-item>
    <el-form-item label="入口车货总重" prop="enweight">
      <el-input v-model="dataForm.enweight" placeholder="入口车货总重"></el-input>
    </el-form-item>
    <el-form-item label="入口轴数" prop="enaxlecount">
      <el-input v-model="dataForm.enaxlecount" placeholder="入口轴数"></el-input>
    </el-form-item>
    <el-form-item label="通行标识ID" prop="passid">
      <el-input v-model="dataForm.passid" placeholder="通行标识ID"></el-input>
    </el-form-item>
    <el-form-item label="出口车道编号,按照编码规则的收费车道编号规则填写" prop="extolllaneid">
      <el-input v-model="dataForm.extolllaneid" placeholder="出口车道编号,按照编码规则的收费车道编号规则填写"></el-input>
    </el-form-item>
    <el-form-item label="出口收费站名称" prop="exstationname">
      <el-input v-model="dataForm.exstationname" placeholder="出口收费站名称"></el-input>
    </el-form-item>
    <el-form-item label="出口收费站Id" prop="exstationid">
      <el-input v-model="dataForm.exstationid" placeholder="出口收费站Id"></el-input>
    </el-form-item>
    <el-form-item label="入口收费站名称" prop="enstationname">
      <el-input v-model="dataForm.enstationname" placeholder="入口收费站名称"></el-input>
    </el-form-item>
    <el-form-item label="入口收费站编号" prop="enstationid">
      <el-input v-model="dataForm.enstationid" placeholder="入口收费站编号"></el-input>
    </el-form-item>
    <el-form-item label="出口车道车型" prop="lanetype">
      <el-input v-model="dataForm.lanetype" placeholder="出口车道车型"></el-input>
    </el-form-item>
    <el-form-item label="出口车道hex" prop="extolllanehex">
      <el-input v-model="dataForm.extolllanehex" placeholder="出口车道hex"></el-input>
    </el-form-item>
    <el-form-item label="插入时间" prop="ceInserttime">
      <el-input v-model="dataForm.ceInserttime" placeholder="插入时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          mediatype: '',
          mediano: '',
          transpaytype: '',
          obusign: '',
          obuid: '',
          cardid: '',
          etccardtype: '',
          extime: '',
          vehicleid: '',
          vehicletype: '',
          vehicleclass: '',
          exweight: '',
          axlecount: '',
          entolllaneid: '',
          entolllanehex: '',
          entime: '',
          enweight: '',
          enaxlecount: '',
          passid: '',
          extolllaneid: '',
          exstationname: '',
          exstationid: '',
          enstationname: '',
          enstationid: '',
          lanetype: '',
          extolllanehex: '',
          ceInserttime: ''
        },
        dataRule: {
          mediatype: [
            { required: true, message: '通行介质 1位数字
1-OBU
2-CPC卡
3-纸券
9-无通行介质不能为空', trigger: 'blur' }
          ],
          mediano: [
            { required: true, message: '介质编码不能为空', trigger: 'blur' }
          ],
          transpaytype: [
            { required: true, message: '交易支付方式:1.出口ETC通行;2.出口ETC刷卡通行.不能为空', trigger: 'blur' }
          ],
          obusign: [
            { required: true, message: 'OBU单/双片标识不能为空', trigger: 'blur' }
          ],
          obuid: [
            { required: true, message: 'OBU序号编码不能为空', trigger: 'blur' }
          ],
          cardid: [
            { required: true, message: 'ETC卡编号不能为空', trigger: 'blur' }
          ],
          etccardtype: [
            { required: true, message: 'ETC卡类别不能为空', trigger: 'blur' }
          ],
          extime: [
            { required: true, message: '出口交易时间不能为空', trigger: 'blur' }
          ],
          vehicleid: [
            { required: true, message: '实际车辆车牌号码+颜色不能为空', trigger: 'blur' }
          ],
          vehicletype: [
            { required: true, message: '收费车型不能为空', trigger: 'blur' }
          ],
          vehicleclass: [
            { required: true, message: '车种不能为空', trigger: 'blur' }
          ],
          exweight: [
            { required: true, message: '出口重量不能为空', trigger: 'blur' }
          ],
          axlecount: [
            { required: true, message: '轴数不能为空', trigger: 'blur' }
          ],
          entolllaneid: [
            { required: true, message: '入口车道编号不能为空', trigger: 'blur' }
          ],
          entolllanehex: [
            { required: true, message: '入口车道hex不能为空', trigger: 'blur' }
          ],
          entime: [
            { required: true, message: '入口交易发生的时间不能为空', trigger: 'blur' }
          ],
          enweight: [
            { required: true, message: '入口车货总重不能为空', trigger: 'blur' }
          ],
          enaxlecount: [
            { required: true, message: '入口轴数不能为空', trigger: 'blur' }
          ],
          passid: [
            { required: true, message: '通行标识ID不能为空', trigger: 'blur' }
          ],
          extolllaneid: [
            { required: true, message: '出口车道编号,按照编码规则的收费车道编号规则填写不能为空', trigger: 'blur' }
          ],
          exstationname: [
            { required: true, message: '出口收费站名称不能为空', trigger: 'blur' }
          ],
          exstationid: [
            { required: true, message: '出口收费站Id不能为空', trigger: 'blur' }
          ],
          enstationname: [
            { required: true, message: '入口收费站名称不能为空', trigger: 'blur' }
          ],
          enstationid: [
            { required: true, message: '入口收费站编号不能为空', trigger: 'blur' }
          ],
          lanetype: [
            { required: true, message: '出口车道车型不能为空', trigger: 'blur' }
          ],
          extolllanehex: [
            { required: true, message: '出口车道hex不能为空', trigger: 'blur' }
          ],
          ceInserttime: [
            { required: true, message: '插入时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/product/cktxetc/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.mediatype = data.cktxEtc.mediatype
                this.dataForm.mediano = data.cktxEtc.mediano
                this.dataForm.transpaytype = data.cktxEtc.transpaytype
                this.dataForm.obusign = data.cktxEtc.obusign
                this.dataForm.obuid = data.cktxEtc.obuid
                this.dataForm.cardid = data.cktxEtc.cardid
                this.dataForm.etccardtype = data.cktxEtc.etccardtype
                this.dataForm.extime = data.cktxEtc.extime
                this.dataForm.vehicleid = data.cktxEtc.vehicleid
                this.dataForm.vehicletype = data.cktxEtc.vehicletype
                this.dataForm.vehicleclass = data.cktxEtc.vehicleclass
                this.dataForm.exweight = data.cktxEtc.exweight
                this.dataForm.axlecount = data.cktxEtc.axlecount
                this.dataForm.entolllaneid = data.cktxEtc.entolllaneid
                this.dataForm.entolllanehex = data.cktxEtc.entolllanehex
                this.dataForm.entime = data.cktxEtc.entime
                this.dataForm.enweight = data.cktxEtc.enweight
                this.dataForm.enaxlecount = data.cktxEtc.enaxlecount
                this.dataForm.passid = data.cktxEtc.passid
                this.dataForm.extolllaneid = data.cktxEtc.extolllaneid
                this.dataForm.exstationname = data.cktxEtc.exstationname
                this.dataForm.exstationid = data.cktxEtc.exstationid
                this.dataForm.enstationname = data.cktxEtc.enstationname
                this.dataForm.enstationid = data.cktxEtc.enstationid
                this.dataForm.lanetype = data.cktxEtc.lanetype
                this.dataForm.extolllanehex = data.cktxEtc.extolllanehex
                this.dataForm.ceInserttime = data.cktxEtc.ceInserttime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/product/cktxetc/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'mediatype': this.dataForm.mediatype,
                'mediano': this.dataForm.mediano,
                'transpaytype': this.dataForm.transpaytype,
                'obusign': this.dataForm.obusign,
                'obuid': this.dataForm.obuid,
                'cardid': this.dataForm.cardid,
                'etccardtype': this.dataForm.etccardtype,
                'extime': this.dataForm.extime,
                'vehicleid': this.dataForm.vehicleid,
                'vehicletype': this.dataForm.vehicletype,
                'vehicleclass': this.dataForm.vehicleclass,
                'exweight': this.dataForm.exweight,
                'axlecount': this.dataForm.axlecount,
                'entolllaneid': this.dataForm.entolllaneid,
                'entolllanehex': this.dataForm.entolllanehex,
                'entime': this.dataForm.entime,
                'enweight': this.dataForm.enweight,
                'enaxlecount': this.dataForm.enaxlecount,
                'passid': this.dataForm.passid,
                'extolllaneid': this.dataForm.extolllaneid,
                'exstationname': this.dataForm.exstationname,
                'exstationid': this.dataForm.exstationid,
                'enstationname': this.dataForm.enstationname,
                'enstationid': this.dataForm.enstationid,
                'lanetype': this.dataForm.lanetype,
                'extolllanehex': this.dataForm.extolllanehex,
                'ceInserttime': this.dataForm.ceInserttime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
